package com.yanqu.road.server.manager.config;

import com.yanqu.road.entity.config.skin.SkinInfo;
import com.yanqu.road.entity.enums.eSkinType;
import com.yanqu.road.logic.bussiness.config.SkinConfigBusiness;
import com.yanqu.road.server.TempMgr;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author wpj
 * @Date 2020/9/1
 */
public class SkinMgr extends TempMgr {

    private static Map<Integer, SkinInfo> skinInfoMap;

    public static SkinInfo getSkinInfo(int skinId) {
        return skinInfoMap.get(skinId);
    }

    public static Map<Integer, SkinInfo> getSkinInfoMap() {
        return skinInfoMap;
    }

    protected static Logger logger = LogManager.getLogger(SkinMgr.class.getName());

    @Override
    public boolean reloadConfig() throws Exception {
        skinInfoMap = SkinConfigBusiness.getSkinInfoMap();

        // return !isPatronsSkillRepeat(skinInfoMap);
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean stop() {
        return false;
    }

    public boolean isPartonsSkillRepeat() {
        Map<Integer, Integer> skillIdMap = new HashMap<>();
        for (SkinInfo skinInfo : skinInfoMap.values()) {
            if (skinInfo.getType() != eSkinType.Patrons.getValue()) {
                continue;
            }

            for (Integer skillId : skinInfo.getSkinEffect()) {
                if (skillIdMap.containsKey(skillId)) {
                    logger.info("门客皮肤技能重复！skinId={}&{},skillId={}", skillIdMap.get(skillId), skinInfo.getSkinId(), skillId);
                    return true;
                }

                skillIdMap.put(skillId, skinInfo.getSkinId());
            }
        }

        return false;
    }
}
